package com.sjh.net.interceptor

import com.sjh.net.HttpOptions
import com.sjh.net.StringResponseBody
import okhttp3.Interceptor
import okhttp3.Protocol
import okhttp3.Response
import org.json.JSONObject

/**
 * 模拟网络请求
 * @author Extends
 * @date 2020/6/23
 */
class HookInterceptor: BaseInterceptor() {
    override fun intercept(chain: Interceptor.Chain): Response {
        val request = chain.request()
        val json = request.header(HttpOptions.TestData)

        val data = try {
            JSONObject(json!!).toString()
        }catch (e:Exception){
            e.printStackTrace()
            json?:""
        }



        return Response.Builder()
            .request(request)
            .protocol(Protocol.HTTP_1_1)
            .code(200)
            .message("success")
            .body(StringResponseBody(data)).build()
    }
}